package com.mqz.zebraEcommerce.commodity.web;

import com.mqz.zebraEcommerce.commodity.entity.CategoryEntity;
import com.mqz.zebraEcommerce.commodity.service.CategoryService;
import com.mqz.zebraEcommerce.commodity.vo.CategoryLevel2VO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @RequestMapping(value = {"/", "/index.html"})
    private String indexPage(Model model) {
        List<CategoryEntity> categoriesLevel1 = categoryService.getCategoriesLevel1();
        model.addAttribute("categoriesLevel1", categoriesLevel1);
        return "index";
    }

    @GetMapping("index/catalog.json")
    @ResponseBody
    public Map<String, List<CategoryLevel2VO>> getCategoriesLevel2() {
        return categoryService.getCategoriesLevel2();
    }

}
